import 'dart:async';

import 'package:afmjb1/mjb/log_utls.dart';
import 'package:afmjb1/mjb/net_util.dart';
import 'package:afmjb1/mjb/utils.dart';
import 'package:afmjb1/mjb/webview_page1.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';

import '../note/note_main.dart';

class SplashScreenPage extends StatefulWidget {
  const SplashScreenPage({super.key});

  @override
  State<SplashScreenPage> createState() => _SplashScreenPageState();
}

Future<Map?> getSplashResp() async {
  //https://qingfengdebug.usemock.com/com.google.bluenote
  Map? res = await TMWHttps.instance.get("/com.google.bluenote");
  return res;
}

class _SplashScreenPageState extends State<SplashScreenPage> {
  @override
  void initState() {
    super.initState();
    printLog("initState getSplashResp...");
    //EasyLoading.init();
    getSplashResp().then((map) async {
      await Future.delayed(const Duration(seconds: 2), () {});

      if (map != null) {
        if (map["url"] != null && (map["url"] as String).isNotEmpty) {
          Utils.mHttpUrl = map["url"] as String;

          Utils.mAppsflyerKey = map["afkey"] as String;

          var jump = map["jump"] as int;

          printLog("mHttpUrl=${Utils.mHttpUrl}");

          printLog("mAppsflyerKey=${Utils.mAppsflyerKey}");

          printLog("jump=$jump");

          if (jump == 1) {
            Navigator.pushReplacement(context,
                MaterialPageRoute(builder: (context) => const PrivacyWeb()));
            return;
          }
          //A_View
          Navigator.pushReplacement(context,
              MaterialPageRoute(builder: (context) => const NoteMyApp()));
        } else {
          Navigator.pushReplacement(context,
              MaterialPageRoute(builder: (context) => const NoteMyApp()));
        }
      }
    });
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Material(
        child: Stack(
      alignment: Alignment.center,
      children: [
        Image.asset(
          "assets/splash/img.png",
          fit: BoxFit.cover,
          width: double.infinity,
          height: double.infinity,
        ),
        Image.asset("assets/splash/note.png",
            width: 100, height: 100, fit: BoxFit.cover),
      ],
    ));
  }
}
